The following example illustrates how to use a movie data export component to export audio data to an AIFF file.
The first step in using a movie data export component to create an AIFF file is instantiating an AIFF data export component. An example of this is shown in Listing 11-2 .
Listing 2 Instantiating a data export component
ComponentDescription cd;
MovieExportComponent ci;
cd.componentType = MovieExportType;
cd.componentSubType = 'AIFF';
cd.componentManufacturer = 0;
cd.componentFlags = canMovieExportFromProcedures;
cd.componentFlagsMask = canMovieExportFromProcedures;
ci = OpenComponent(FindNextComponent(nil, &cd));
Once an AIFF movie data export component has been instantiated, it must be configured to open a single output audio stream. Listing 11-3 is an example of creating an output audio stream by calling MovieExportAddDataSource. In this example, MovieExportAddDataSource also provides the callback functions for supplying media data.
Listing 3 Configuring the audio export component
#define kMySampleRate 22050
#define kSoundBufferSize 1024
typedef struct
{
Ptr soundData;
SoundDescriptionHandle soundDescription;
long trackID;
}
MyReferenceRecord;
MyReferenceRecord myRef;
SoundDescriptionPtr sdp;
myRef.soundData = NewPtr(kSoundBufferSize);
myRef.soundDescription = NewHandleClear(sizeof(SoundDescription));
sdp = *myRef.soundDescription;
sdp->descSize = sizeof(SoundDescription);
sdp->dataFormat = kRawCodecType;
sdp->numChannels = 1;
sdp->sampleSize = 8;
sdp->sampleRate = kMySampleRate << 16;
MovieExportAddDataSource(ci, SoundMediaType, kMySampleRate,
&myRef.trackID, getSoundPropertyProc,
getSoundDataProc, &myRef);
The export operation takes place when all of the required output tracks have been created.
Listing 4 Exporting audio data
StandardFileReply reply;
Handle dataRef;
// get output file from user
QTNewAlias(&reply.sfFile, (AliasHandle *)&dataRef, true);
MovieExportFromProceduresToDataRef(ci, dataRef, rAliasType);
MovieExportFromProceduresToDataRef calls the two functions specified in MovieExportAddDataSource to obtain data to generate the output file. The first function returns information about the output track's properties, including the sample rate and supported media. If no value is returned for a particular property, the exporter specifies a default value based on the source data format. In the example in Listing 11-5 , the output sample rate is set at 32000 hz, with all other properties left unspecified.
Listing 5 Obtaining output track information
pascal OSErr getSoundTrackPropertyProc(void *refcon, long trackID,
OSType propertyType, void *propertyValue)
{
OSErr err = noErr;
switch (propertyType)
{
case scSoundSampleRateType:
*(Fixed *)propertyValue = 32000L << 16;
break;
default:
err = paramErr;
break;
}
return err;
}
The second function provides data to be exported. Listing 11-6 shows a block of sound data (silence) returned for each export request. The export operation ends when this function returns eofErr .
Listing 6 Providing output track information to the export component
pascal OSErr getTrackDataProc(void *refCon,
MovieExportGetDataParams *params)
{
MyReferenceRecord *myRef = (MyReferenceRecord *)refCon;
if (params->requestedTime > kMySampleRate * 10)
return eofErr;// end of data after 10 seconds
params->dataPtr = myRef->soundData;
params->dataSize = kSoundBufferSize;
params->actualTime = params->requestedTime;
params->sampleCount = kSoundBufferSize;
params->durationPerSample = 1;
params->descType = SoundMediaType;
params->descSeed = 1;
params->desc = (SampleDescriptionHandle)myRef->soundDescription;
return noErr;
}
| Previous | Chapter contents | Chapter top | Section top | Next |